<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>权限与模块对应关系配置页</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<link rel="stylesheet" href="res/css/list.css" type="text/css" />
		<script type="text/javascript" src="res/js/jquery-1.2.6.js"></script>
		<script type="text/javascript" src="res/js/util.js"></script>
		<script type="text/javascript">
			//表彰提交验证
			function check() {
				var powerId = document.getElementById("powerId").value;
				if(powerId == -1 || powerId == 0) {
					alert("请选择权限！");
					return false;
				}
				var ids = [];
				var chks = document.getElementsByName("chk");
				for(var i = 0;i<chks.length;i++) {
					if (chks[i].checked == true) {
						ids.push(chks[i].value);
					}
				}
				if(ids.length == 0) {
					alert("请选择模块！");
					return false;
				}
				if(confirm("确定要提交吗？")) {
					return true;
				}
				return false;
			}
			//根据用户组ID，获得该用户组的权限
			function loadModule(id) {
				var chks = document.getElementsByName("chk");
				if(id == -1 || id == 0) {
					for(var i = 0;i<chks.length;i++) {
						chks[i].checked = false;
					}
					return ;
				}
				$.post("manager/loadModulesByPower.action",{"powerId":id},function(data){
					var json = eval(data);
					var modules = json.powerModules;
					if(modules != null) {
						for(var i = 0;i<chks.length;i++) {
							chks[i].checked = false;
						}
						for(var i = 0;i<modules.length;i++) {
							var item = modules[i];
							for(var j = 0;j<chks.length;j++) {
								if(item.moduleId == chks[j].value) {
									chks[j].checked = true;
								}
							}
						}
					}
				},"json");
			}
		</script>
	</head>

	<body>
		<form action="manager/proPowerModule.action" method="post" onsubmit="return check();">
			<table width="100%" border="0" align="center" cellpadding="2"
				cellspacing="1" bordercolor="#799AE1" class="tableBorder">
				<tbody>
					<tr>
						<td align="center" colspan="2"
							style="height: 23px; background: #4455aa; color: white; font-weight: bold;">
							<s:property value="nodeText" />
						</td>
					</tr>
					<tr bgcolor="#DEE5FA">
						<td colspan="2" align="left" class="txlrow">
							<select name="powerId" id="powerId" style="width:100%;" onchange="javascript:loadModule(this.value);" >
								<s:if test="powers == null || powers.size() == 0">
									<option value="-1">
										暂无数据
									</option>
								</s:if>
								<s:else>
									<option value="0">
										请选择
									</option>
									<s:iterator value="powers">
										<option value="<s:property value='id' />">
											<s:property value="typeName" />
										</option>
									</s:iterator>
								</s:else>
							</select>
						</td>
					</tr>
					<tr align="center" bgcolor="#799AE1">
						<td width="4%" align="center" class=txlHeaderBackgroundAlternate>
							选定
						</td>
						<td width="96%" align="center"
							class="txlHeaderBackgroundAlternate">
							模块名称
						</td>
					</tr>
					<s:if test="modules==null || modules.size() == 0">
						<tr bgcolor="#DEE5FA">
							<td colspan="2" align="center" class="txlrow">
								暂无数据！
							</td>
						</tr>
					</s:if>
					<s:else>
						<s:iterator value="modules">
							<tr bgcolor="#DEE5FA">
								<td align=center class=txlrow>
									<input type="checkbox" name="chk"
										value="<s:property value='id'/>">
								</td>
								<td align="center" class="txlrow">
									<s:property value="moduleName" />
								</td>
							</tr>
						</s:iterator>
					</s:else>
					<tr bgcolor="#DEE5FA">
						<td colspan="2" align="center" bgcolor="#DEE5FA" class="txlrow">
							<span class="tablebody2"> <input type="button" value="全选"
									name="Submit2" onClick="javascript:selectAll()" /> <input
									type="button" value="取消全选" name="Submit2"
									onClick="javascript:unSelectAll();" /> <input type="submit"
									value="提交" name="Submit2" />
							</span>
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</body>
</html>
